package app.Controller;

import Api.MailServer.mailserver;
import app.Service.Checkaccount;
import app.Service.Mailservice;
import common.result.CodeEnum;
import common.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Controller implements mailserver {
    @Autowired
    Mailservice mailservice;
    @Autowired
    Checkaccount checkaccount;

    @Override
    @GetMapping("/MailServer")
    public ResponseResult MailServer(@RequestParam(value = "account", required = true) String account) {
        if (!checkaccount.isEmail(account)) {
            return new ResponseResult(CodeEnum.MAIL_FORMATE_ERROR.getCode(), CodeEnum.MAIL_FORMATE_ERROR.getMessage());
        }
        return mailservice.sendMail(account);
    }

}
